package net.child.chess.pieces;

import java.util.List;
import net.child.chess.R;
import net.child.chess.utils.ChessDef;
import net.child.chess.utils.Position;

public class Rook extends PowerfullPiece 
{
	public Rook(ChessDef.Color color, int position)
	{
		super(color, Piece.Type.ROOK, initialState(position, color), imageId(color));		
	}
	
	@Override
	public void attacks(List<Integer> squares, IMoves iMoves)
	{
		rookAttacks(squares, iMoves);
	}
	
	private static int imageId(ChessDef.Color color)
	{
		if(color == ChessDef.Color.BLACK)
		{
			return R.drawable.ic_black_rook;
		}
		else
		{
			return R.drawable.ic_white_rook;
		}
	}
	
	static private PieceState initialState(int position, ChessDef.Color color)
	{
		Position pos = new Position(position); 
		if(color == ChessDef.Color.BLACK)
		{
			return new PieceState(pos, (pos.y() != 0) || ((pos.x() != 0) && (pos.x() != 7)));
		}
		else
		{
			return new PieceState(pos, (pos.y() != 7) || ((pos.x() != 0) && (pos.x() != 7)));
		}
	}
}

